﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MpSoft.Library.BUSS.Settings; 

namespace MpSoft.Web.AdminCP.Controls.Configs
{
    public partial class SetEmail : System.Web.UI.UserControl
    {
        #region Method

        private void BindControl()
        {
            txtEmail.Text = SettingBUSS.GetSettingValue("email.email");
            txtPassword.Text = SettingBUSS.GetSettingValue("email.password");
            txtPort.Text = SettingBUSS.GetSettingValue("email.port");
            txtHost.Text = SettingBUSS.GetSettingValue("email.host");
        }

        public int Save()
        {
            var email = SettingBUSS.Setting_ByKey("email.email");
            // email
            email.SettingValue = txtEmail.Text;
            email.SettingGroup = "email";
            SettingBUSS.Setting_Update(email);
            //password 
            email = SettingBUSS.Setting_ByKey("email.password");
            email.SettingValue = txtPassword.Text;
            email.SettingGroup = "email";
            SettingBUSS.Setting_Update(email);
            //port
            email = SettingBUSS.Setting_ByKey("email.port");
            email.SettingValue = txtPort.Text;
            email.SettingGroup = "email";
            SettingBUSS.Setting_Update(email);
            //host
            email = SettingBUSS.Setting_ByKey("email.host");
            email.SettingValue = txtHost.Text;
            email.SettingGroup = "email";
            SettingBUSS.Setting_Update(email);
            return 1;
        }

        #endregion

        #region Event

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindControl();
        }

        #endregion
    }
}